<?php
namespace app\admin\controller;

use app\admin\builder\Form;
use app\admin\builder\Table;

class Index extends Admin
{
    public function initialize()
    {
        parent::initialize();
    }


    public function _leftSlide()
    {

        $slide = [
            ['title' => '表单', 'child' => [
                ['menu' => 'admin/index/index', 'query' => ['sss' => 222], 'title' => '表单', 'slide_name' => 'form'],
            ]],
            ['title' => '表格', 'child' => [
                ['menu' => 'admin/index/table', 'title' => '表格', 'slide_name' => 'table'],
            ]]
        ];

        return $slide;
    }


    public function index()
    {
        $form = new Form();
        if (Request()->isPost()) {
            $form->saveConfig();

        } else {

            $option = [
                ['value' => 'hangzhou', 'title' => '杭州'],
                ['value' => 'huzhou', 'title' => '湖州'],
                ['value' => 'jiaxing', 'title' => '嘉兴'],
                ['value' => 'shanghai', 'title' => '上海'],
            ];
            $option1 = [
                // ''=>'',
                'hangzhou' => '杭州',
                'huzhou' => '湖州',
                'jiaxing' => '嘉兴',
                'shanghai' => '上海',

            ];
            $data = [
                'text' => '这是标题的值',
                'password' => '123456',
                'switch' => '1',
                'select' => 'huzhou',
                'checkbox' => 'jiaxing,huzhou',
                'radio' => 'jiaxing',
                'textarea' => '简介~~~~~',
                'editor' => '详情介绍~~',
                'area' => '330000,330400,330421'
            ];
            //$data =[];
            $this->_setSlide('form');
            return $form->setTitle('ssss')
                ->form(url('index'))
                ->typeText('text', '标题', ['add_btn' => [['text' => '获取', 'data-role' => 'sdfdsf', 'class' => 'sdfsdf'], ['text' => '获取aa', 'data-role' => 'sdfdsf', 'class' => 'layui-btn-warm']]])
                ->typeUploadImage('image1', '上传图片')
                ->typePassword('password', '密码')
                ->typeSwitch('switch', '开关', ['text' => '开|关'])
                ->typeArea('area', '地区')
                // ->typeSwitch('switch1', '开关',['text'=>'开|关'))
                ->typeSelect('select', 'hhh', ['option' => $option1])
                ->typeCheckbox('checkbox', 'abc', ['option' => $option])
                ->typeRadio('radio', 'def', $option)
                ->typeTextarea('textarea', 'fff', [])
                ->typeTime('time', 'time', [])
                ->typeEditor('editor', 'fff', '')
                // ->setData($data)
                ->show();
        }

    }


    public function table()
    {
        $table = new Table();
        if (Request()->isPost()) {


        } else {

            $option = [
                ['value' => 'hangzhou', 'title' => '杭州'],
                ['value' => 'huzhou', 'title' => '湖州'],
                ['value' => 'jiaxing', 'title' => '嘉兴'],
                ['value' => 'shanghai', 'title' => '上海'],
            ];
            $option1 = [
                // ''=>'',
                'hangzhou' => '杭州',
                'huzhou' => '湖州',
                'jiaxing' => '嘉兴',
                'shanghai' => '上海',

            ];
            $data = [
                'text' => '这是标题的值',
                'password' => '123456',
                'switch' => '1',
                'select' => 'huzhou',
                'checkbox' => 'jiaxing,huzhou',
                'radio' => 'jiaxing',
                'textarea' => '简介~~~~~',
                'editor' => '详情介绍~~',
            ];
            //$data =[];


            $r = 30;
            $map = [];
            $data = model('user/User')->paginate($r);
            if (is_object($data)) {
                $data = $data->toArray();
            }
            $this->_setSlide('table');

            return $table->setTitle('ssss')
                ->dataSource($data, 'user')
                ->button('获取选中项', ['data-role' => 'get_checked'])
                ->field('id', 'ID')
                ->field('username', '名称')
                ->field('nickname', '昵称')
                ->fieldStatus('status', '状态')
                ->action('编辑', ['url' => url('edit'), 'class' => 'layui-btn-primary'])
                ->action('删除', ['url' => url('delete'), 'class' => 'layui-btn-danger'])
                ->show();
        }

    }



}
